import { Type } from 'class-transformer';
import {
  IsArray,
  IsNotEmpty,
  IsNumber,
  IsOptional,
  IsString,
  MaxLength,
  Min,
  ValidateNested,
} from 'class-validator';

class SpecsType {
  @IsNumber()
  @IsNotEmpty()
  specsId: number;
  
  @IsString()
  @MaxLength(50)
  @IsNotEmpty()
  specsName: string;

  @IsString()
  @IsNotEmpty()
  specsUnit: string;

  @IsNumber()
  @IsNotEmpty()
  price: number;

  @IsNumber()
  @IsNotEmpty()
  promotionPrice: number;

  @IsNumber()
  @Min(0)
  @IsNotEmpty()
  inventory: number;
}

export class CreateNewDto {
  @IsNotEmpty()
  categoryId: number;

  @IsNotEmpty()
  goodsId: number;

  @IsNotEmpty()
  @IsString()
  title: string;

  @IsNotEmpty()
  @IsString()
  desc: string;

  @IsNotEmpty()
  @IsArray()
  advertisePic: Array<{ url: string }>;

  @IsNotEmpty()
  @ValidateNested()
  @Type(() => Array<SpecsType>)
  specsList: Array<SpecsType>;

  @IsOptional()
  @IsArray()
  fileList: Array<{ url: string }>;

  @IsOptional()
  @IsArray()
  detail: Array<{ url: string }>;
}
